package com.wdh.minio.event;

import com.wdh.minio.bean.PayResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
@Slf4j(topic = "PayResultListener")
public class PayResultListener {

    @EventListener(PayResultEvent.class)
    @Async
    public void onApplicationEvent(PayResultEvent event) {
        log.info(event.getMessage());
        PayResult source = (PayResult)event.getSource();
        try {
            TimeUnit.SECONDS.sleep(5);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        log.info(source.getPayStatus());
    }
}
